package cn.ffcs.uec.common.component;

import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zul.Tree;

import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uom.common.zkplus.zul.tree.model.BaseTreeModel;
import cn.ffcs.uom.common.zkplus.zul.tree.node.impl.TreeNodeImpl;
import cn.ffcs.uom.common.zkplus.zul.tree.render.BaseTreeitemRenderer;
import lombok.Getter;
import lombok.Setter;

public class UecBdDefdocTree extends Tree implements IdSpace {

    private static final long serialVersionUID = -7395972075608785723L;

    @Getter
    @Setter
    private UecBdDefdocTreeBandboxExt uecBdDefdocTreeBandboxExt;

    public UecBdDefdocTree() {
        Components.wireVariables(this, this);
        Components.addForwards(this, this, '$');
    }

    public void onCreate() {
        this.setSclass("zt-tree-scroll");
        bindTree();
    }

    /**
     * 根据指定flag 展示指定根节点标识
     */
    @Getter
    private String flag;

    public void setFlag(String flag) {
        this.flag = flag;
        bindTree();
    }

    /**
     * 初始化树结构
     */
    @SuppressWarnings("deprecation")
    public void bindTree() {
        UecBdDefdoc uecBdDefdoc = UecBdDefdoc.newInstance();
        uecBdDefdoc.setIsRoot(true);
        uecBdDefdoc.setFlag(flag);
        if (uecBdDefdocTreeBandboxExt != null) {
            uecBdDefdoc.setComponent(uecBdDefdocTreeBandboxExt);
        }
        final TreeNodeImpl<UecBdDefdoc> treeNode = new TreeNodeImpl<UecBdDefdoc>(uecBdDefdoc);
        treeNode.readChildren();
        this.setModel(new BaseTreeModel(treeNode));
        if (uecBdDefdocTreeBandboxExt != null) {
            this.setItemRenderer(new UecBdDefdocTreeitemRenderer(uecBdDefdocTreeBandboxExt));
        } else {
            this.setTreeitemRenderer(new BaseTreeitemRenderer());
        }
    }
}
